﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Repository;
using Model;
using UI.Models;

namespace UI.Controllers
{
    public class ProjectController : Controller
    {
        //
        // GET: /Project/

        public ActionResult Index()
        {
            var repository = RepositoryManager.CreateTKNTCategoryRepository();
            List<tkntCategory> litCategory = repository.GetAll();
            return View(litCategory);
        }

        public ActionResult Category(int id)
        {
            var repository = RepositoryManager.CreateTKNTProductRepository();
            var repositoryImg = RepositoryManager.CreateTKNTImageRepository();
            List<tkntProduct> liProduct = repository.GetAllByCategoryIDNoImage(id);
            List<tkntProjectModel> liProject = new List<tkntProjectModel>();

                foreach (var t in liProduct)
                {
                    tkntProjectModel tkntProject = new tkntProjectModel();
                    tkntProject.otkntProduct = t;
                    string Url = repositoryImg.GetAvartar(t.Id);
                    if (!string.IsNullOrEmpty(Url))
                        tkntProject.Url = Url;
                    else
                        tkntProject.Url = "~/Images/no-image.gif";

                    liProject.Add(tkntProject);
                }
                ViewData["Category"] = id;
                return View(liProject);
        }

        public ActionResult Detail(int id)
        {
            var repository = RepositoryManager.CreateTKNTProductRepository();
            tkntProduct otknt = repository.HaveImage(id);

            return View(otknt);
        }
    }
}
